package com.exam.sacrifice.ui.adapter;

import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;

import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.exam.sacrifice.R;
import com.exam.sacrifice.bean.GongPinInfo;
import com.exam.sacrifice.ui.bean.RechargeInfo;
import com.makeramen.roundedimageview.RoundedImageView;

public class GongPinAdapter extends BaseQuickAdapter<GongPinInfo, BaseViewHolder> {

    private OnItemClickListener listener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        listener = onItemClickListener;
    }

    public GongPinAdapter() {
        super(R.layout.item_layout_gongpin, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, GongPinInfo item) {

        helper.setText(R.id.tv_name, item.name);
        RoundedImageView imageView = helper.getView(R.id.iv_src);
        imageView.setImageResource(item.src);

        TextView tvNum = helper.getView(R.id.tv_num);
        TextView tvFee = helper.getView(R.id.tv_fee);
        helper.getView(R.id.iv_jian).setOnClickListener(view -> {
            int num = Integer.parseInt(tvNum.getText().toString());
            if (num <= 1) {
                num = 1;
            } else {
                --num;
            }
            tvNum.setText(num + "");
            tvFee.setText(num * 2 + "");
        });
        helper.getView(R.id.iv_jia).setOnClickListener(view -> {
            int num = Integer.parseInt(tvNum.getText().toString());
            ++num;
            tvNum.setText(num + "");
            tvFee.setText(num * 2 + "");
        });
        helper.getView(R.id.ll_pay).setOnClickListener(view -> {
            int num = Integer.parseInt(tvNum.getText().toString());
            item.buyCount = num;
            listener.onItemClick(item);
        });
    }

    public interface OnItemClickListener {
        void onItemClick(GongPinInfo messageInfo);
    }
}
